package com.kvc.extend.papervision3d
{
	import flash.display.BitmapData;
	import flash.display.Shape;
	
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.objects.primitives.Plane;
	
	public class FloorPlane3D extends Plane
	{
		public function FloorPlane3D(material:MaterialObject3D=null, width:Number=0, height:Number=0, segmentsW:Number=0, segmentsH:Number=0)
		{
			super(material, 1000, 1000, 4, 4);
			this.rotationX=90;
			this.y=-500;
			
			
			var material:MaterialObject3D=createMovieClipGrid();
			material.doubleSided=true;
			this.material=material;
		}
		
		private function createMovieClipGrid():MovieMaterial{
			var shape:Shape=new Shape();
			shape.graphics.beginFill(0xDDDDDD,.5);
			shape.graphics.drawRect(0,0,4,4);
			shape.graphics.drawRect(4,4,4,4);
			shape.graphics.beginFill(0xff0000,.1);
			shape.graphics.drawRect(0,4,4,4);
			shape.graphics.drawRect(4,0,4,4);
			shape.graphics.endFill();
			
			var movieMat:MovieMaterial=new MovieMaterial(shape,true);
			movieMat.tiled=true;
			movieMat.maxU=10,movieMat.maxV=10;
			return movieMat;
		}
		
		private function createBitmapGrid():BitmapMaterial{
			var bmd:BitmapData = new BitmapData(2, 2,false);
			bmd.setPixel(0, 0, 0xDDDDDD);
			bmd.setPixel(0, 1, 0x333333);
			bmd.setPixel(1, 0, 0x333333);
			bmd.setPixel(1, 1, 0xDDDDDD);
			
			var floorMat:BitmapMaterial= new BitmapMaterial(bmd, true);
			
			floorMat.tiled = true;
			floorMat.maxU = 10, floorMat.maxV = 10;
			return floorMat;
		}
	}
}